﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 学生选课及成绩查询管理系统
{
    public partial class TeacherLogin : Form
    {
        public TeacherLogin()
        {
            InitializeComponent();
        }

        User user;

        internal User User
        {
            get { return user; }
            set { user = value; }
        }

        internal void Welcome(User user)
        {
            toolStripStatusLabel1.Text = "欢迎用户:" + user.Userid + "_" + user.Username;
        }

        private void toolStripStatusLabel3_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void TeacherLogin_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void TeacherLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否要退出程序", "关闭提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
            else
            {
                Dispose();
                Application.Exit();
            }
        }

        private void 修改个人密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                UpdatePwd up = new UpdatePwd();
                up.User = user;
                up.MdiParent = this;
                up.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 成绩录入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                addStudentScoreInfo assi = new addStudentScoreInfo();
                assi.MdiParent = this;
                assi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
            
        }
        

        private void 查看学生成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                findAllorOneStudentScoreInfo fassi = new findAllorOneStudentScoreInfo();
                fassi.User = user;
                fassi.MdiParent = this;
                fassi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 删除成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                findAllorOneStudentScoreInfo fassi = new findAllorOneStudentScoreInfo();
                fassi.User = user;
                fassi.MdiParent = this;
                fassi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 修改成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                findAllorOneStudentScoreInfo fassi = new findAllorOneStudentScoreInfo();
                fassi.User = user;
                fassi.MdiParent = this;
                fassi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 注销ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1(user);
            f1.Show();
            this.Dispose();
        }

        private void 查看授课班级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                showTeachingClassOfsituation stcos = new showTeachingClassOfsituation();
                stcos.User = user;
                stcos.MdiParent = this;
                stcos.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            } 
            
        }

        private void 学生成绩信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = "select count(*) from teacher where tstate=0 and tno=" + this.user.Username;
            object res =DBAccess.GetOne(sql);
            if ((int)res!=0 )
            {
                MessageBox.Show("您已不是这个学校的老师，无权查看学生成绩信息");
                //学生成绩信息ToolStripMenuItem.Enabled = false;
                成绩录入ToolStripMenuItem.Enabled = false;
                修改成绩ToolStripMenuItem.Enabled = false;
                查看学生成绩ToolStripMenuItem.Enabled = false;
                return;
            }
            
        }
    }
}
